<?php
class UserModel extends Model {
	
	function UserModel() {
		parent::Model ();
	}
	
	function insert_user($data) {
		$this->db->insert ( 'user', $data );
	}
	
	function update_user($id, $data) {
		$this->db->where ( 'id', $id );
		$this->db->update ( 'user', $data );
	}
	
	function del_user($id) {
		$this->db->delete ( 'user', array ('id' => $id ) );
	}
	
	function get_user_by_userid($id) {
		$sql = "SELECT * FROM user WHERE id = ?";
		$query = $this->db->query ( $sql, array ($id ) );
		return $query->result ();
	}
	
	function get_user_by_email($email) {
		$sql = "SELECT * FROM user WHERE email=?";
		$query = $this->db->query ( $sql, array ($email ) );
		$data = $query->result ();
		if (count($data) == 0) {
			return false;
		} else {
			return $data[0];
		}
		
	}
	
	function get_user_by_phone($phone) {
		$sql = "SELECT * FROM user WHERE phone=?";
		$query = $this->db->query ( $sql, array ($phone ) );
		return $query->result ();
	}
}